package com.franklin.ideaplugin.api.ui;

import com.franklin.ideaplugin.api.ui.IBaseComponent;
import com.franklin.ideaplugin.api.utils.SwingUtils;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
import com.intellij.ui.components.JBScrollPane;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;

/**
 * @author Franklin
 * @since 2023/08/08 21:14
 */
public class ToolBarWindowForm implements IBaseToolBarComponent {
    private JPanel mainPanel;
    private JScrollPane scrollPane;
    private JPanel toolPanel;
    private JPanel realPanel;

    private DefaultActionGroup actionGroup;

    public ToolBarWindowForm() {
        this.realPanel.setLayout(SwingUtils.createLayoutManager(1,1));
        this.toolPanel.setLayout(new FlowLayout());
        this.initToolBar();
    }

    /**
     * 初始化工具栏
     */
    private void initToolBar() {
        this.actionGroup = new DefaultActionGroup();
        this.initToolBar(this.actionGroup);
    }

    public void addContent(JComponent content, Dimension size){
        this.addCell(realPanel,content,0,0,size);
    }

    public void addToolButton(@NotNull JButton button){
        this.addToolButton(this.actionGroup,button);
    }

    public void addToolButton(@NotNull AnAction anAction){
        this.actionGroup.add(anAction);
    }

    @Override
    public JComponent getMainPanel() {
        return this.mainPanel;
    }

    private void createUIComponents() {
        // TODO: place custom component creation code here
        this.scrollPane = new JBScrollPane();
    }

    @Override
    public @NotNull JComponent getToolPanel() {
        return this.toolPanel;
    }
}
